//
//  CardView.m
//  YSLDraggingCardContainerDemo
//
//  Created by Veer on 16/6/28.
//

#import "CardView.h"

#import "YAYIRecruitHospitalModel.h"

@interface CardView()

@property (nonatomic, strong) UILabel *hospitalNameLbl;
@property (nonatomic, strong) UILabel *addressLbl;
@property (nonatomic, strong) UILabel *titleLbl;
@property (nonatomic, strong) UILabel *cooperationModelLbl;

/**
 *  底下招聘信息label
 */
@property (nonatomic, weak) UILabel *lbl1_1;
@property (nonatomic, weak) UILabel *lbl1_2;
@property (nonatomic, weak) UILabel *lbl1_3;
@property (nonatomic, weak) UILabel *lbl2_1;
@property (nonatomic, weak) UILabel *lbl2_2;
@property (nonatomic, weak) UILabel *lbl2_3;

@end


@implementation CardView


- (void)setModel:(YAYIRecruitHospitalModel *)model
{
    _model = model;
    
    if ([model.avatar rangeOfString:@"/"].location == NSNotFound) {
        self.imageView.image = [UIImage imageNamed:model.avatar];
    }else{
        NSString *urlStr = [NSString stringWithFormat:@"%@%@",API, model.avatar];
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"home_showImg1"] options:SDWebImageRefreshCached];
    }
    
    self.hospitalNameLbl.text = model.hospitalname;
    self.addressLbl.text = model.hosaddress;
    
    
    if (model.mode == 1) {
        self.cooperationModelLbl.text = @"日租";
    }else{
        self.cooperationModelLbl.text = [NSString stringWithFormat:@"%zd%%分成", model.price];
    }
    
    CGSize size = [self.cooperationModelLbl.text sizeWithFont:self.cooperationModelLbl.font];
    [self.cooperationModelLbl mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.width - size.width - 12 - 12);
        make.width.mas_equalTo(size.width + 12);
    }];
    
    self.titleLbl.text = model.title;
    
    self.lbl1_1.text = model.jobtitle;
}


- (instancetype)init {
    self = [super init];
    if (self) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setup];
    }
    return self;
}


- (void)setup
{
    
    self.backgroundColor = [UIColor whiteColor];
    self.layer.shadowColor = YAYIColor(0x99, 0x99, 0x99).CGColor;
    self.layer.shadowOpacity = 0.6;
    self.layer.shadowRadius = 4;
    
    _imageView = [[UIImageView alloc]init];
    _imageView.backgroundColor = [UIColor whiteColor];
    
    _imageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height * 0.65);
    [self addSubview:_imageView];
    
    UIBezierPath *maskPath;
    maskPath = [UIBezierPath bezierPathWithRoundedRect:_imageView.bounds
                                     byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                           cornerRadii:CGSizeMake(10.0, 10.0)];
    
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = _imageView.bounds;
    maskLayer.path = maskPath.CGPath;
    _imageView.layer.mask = maskLayer;
    
    _selectedView = [[UIView alloc]init];
    _selectedView.frame = _imageView.frame;
    _selectedView.backgroundColor = [UIColor clearColor];
    _selectedView.alpha = 0.0;
    [_imageView addSubview:_selectedView];
    
    // 标示view 不喜欢
    UIView *unlikeView = [[UIView alloc] init];
    unlikeView.alpha = 0;
    [self addSubview:unlikeView];
    self.unlikeView = unlikeView;
    [unlikeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(SCREEN_width - 30 - 100);
        make.top.mas_equalTo(20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(120);
    }];
    
    UIImageView *unlikeImageView = [[UIImageView alloc] init];
    unlikeImageView.image = [UIImage imageNamed:@"unLikeIcon"];
    [unlikeView addSubview:unlikeImageView];
    [unlikeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.width.height.mas_equalTo(unlikeView.mas_width);
    }];
    
    UILabel *unlikeLbl = [[UILabel alloc] init];
    unlikeLbl.text = @"暂不考虑";
    unlikeLbl.textAlignment = NSTextAlignmentCenter;
    unlikeLbl.font = [UIFont systemFontOfSize:17];
    unlikeLbl.textColor = YAYIColor(120, 120, 120);
    [unlikeView addSubview:unlikeLbl];
    [unlikeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(unlikeImageView.mas_bottom);
        make.bottom.mas_equalTo(unlikeView);
        make.width.mas_equalTo(unlikeView);
    }];
    
    // 标示view 喜欢
    UIView *likeView = [[UIView alloc] init];
    likeView.alpha = 0;
    [self addSubview:likeView];
    self.likeView = likeView;
    [likeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(120);
    }];
    
    UIImageView *likeImageView = [[UIImageView alloc] init];
    likeImageView.image = [UIImage imageNamed:@"likeIcon"];
    [likeView addSubview:likeImageView];
    [likeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.width.height.mas_equalTo(unlikeView.mas_width);
    }];
    
    UILabel *likeLbl = [[UILabel alloc] init];
    likeLbl.text = @"感兴趣";
    likeLbl.textAlignment = NSTextAlignmentCenter;
    likeLbl.font = [UIFont systemFontOfSize:17];
    likeLbl.textColor = YAYIColor(68, 148, 228);
    [likeView addSubview:likeLbl];
    [likeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(likeImageView.mas_bottom);
        make.bottom.mas_equalTo(likeView);
        make.width.mas_equalTo(likeView);
    }];
    
    
    //  医院信息label
    UILabel *hospitalNameLbl = [[UILabel alloc] init];
    hospitalNameLbl.font = [UIFont systemFontOfSize:15];
    [self addSubview:hospitalNameLbl];
    self.hospitalNameLbl = hospitalNameLbl;
    [hospitalNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.bottom.mas_equalTo(self.imageView.mas_bottom).offset(60 * YAYIScreenScale * 0.5);
    }];
    
    UILabel *addressLbl = [[UILabel alloc] init];
    addressLbl.text = @"天津市河北区胜利路433号(意大利风情街)";
    addressLbl.font = [UIFont systemFontOfSize:13];
    addressLbl.textColor = YAYIColor(156, 156, 156);
    [self addSubview:addressLbl];
    self.addressLbl = addressLbl;
    [addressLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.centerY.mas_equalTo(hospitalNameLbl.mas_bottom).offset(60 * YAYIScreenScale * 0.25);
    }];
    
    // 合作模式 1.日租 2.分成
    UILabel *cooperationModelLbl = [[UILabel alloc] init];
    cooperationModelLbl.font = [UIFont systemFontOfSize:14];
    cooperationModelLbl.textColor = YAYIColor(96, 167, 237);
//    cooperationModelLbl.text = @"日租";
    cooperationModelLbl.textAlignment = NSTextAlignmentCenter;
    cooperationModelLbl.layer.borderWidth = 1.0;
    cooperationModelLbl.layer.borderColor = YAYIColor(96, 167, 237).CGColor;
    cooperationModelLbl.layer.cornerRadius = 5.0;
    cooperationModelLbl.layer.masksToBounds = YES;
    [self addSubview:cooperationModelLbl];
    self.cooperationModelLbl = cooperationModelLbl;
    [cooperationModelLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.width - 12 - 40);
        make.top.mas_equalTo(hospitalNameLbl).offset(0);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
    }];
    
    // 线
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = YAYIColor(230, 230, 230);
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(self.imageView.mas_bottom).offset(60 * YAYIScreenScale);
        make.width.mas_equalTo(self.width);
        make.height.mas_equalTo(0.5);
    }];
    
    
    UIView *jobContainView = [[UIView alloc] init];
//    jobContainView.backgroundColor = [UIColor yellowColor];
    [self addSubview:jobContainView];
    [jobContainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(lineView.mas_bottom).offset(0);
        make.width.mas_equalTo(self.width);
        make.bottom.mas_equalTo(self.mas_top).offset(self.height - 10);
    }];
    
    // 标题
    UILabel *titleLbl = [[UILabel alloc] init];
//    titleLbl.text = @"合作信息";
    titleLbl.font = [UIFont systemFontOfSize:14];
    titleLbl.textColor = YAYIColor(96, 167, 237);
    [jobContainView addSubview:titleLbl];
    self.titleLbl = titleLbl;
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(8);
        make.height.mas_equalTo(15);
    }];
    
    // 左边兼职信息label
    UILabel *lbl1 = [[UILabel alloc] init];
    lbl1.numberOfLines = 0;
    lbl1.font = [UIFont systemFontOfSize:12];
    lbl1.textColor = YAYIColor(141, 142, 143);
    [jobContainView addSubview:lbl1];
    self.lbl1_1 = lbl1;
    [lbl1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(titleLbl.mas_bottom).offset(4);
        make.right.mas_equalTo(-12);
        make.bottom.mas_lessThanOrEqualTo(0);
    }];
}

@end
